//
//  StarView.m
//  MyMovie
//
//  Created by apple on 16/5/11.
//  Copyright © 2016年 ljp. All rights reserved.
//

#import "StarView.h"
#import "UIViewExt.h"
@interface StarView ()
{
    UIView *_grayView;
    UIView *_yellowView;

}

@end
@implementation StarView

//-(instancetype)initWithFrame:(CGRect)frame {
//
//    self = [super initWithFrame:frame];
//
//    if (self) {
//
//        [self createStarView];
//    }
//    return self;
//}

-(void)awakeFromNib {

    [super awakeFromNib];
    [self createStarView];
    
}
-(void)changeRating:(CGFloat)rating {

    _yellowView.width = rating/10*_grayView.width;

}
-(void)createStarView {

    UIImage *grayStar = [UIImage imageNamed:@"gray"];
    UIImage *yellowStar = [UIImage imageNamed:@"yellow"];

    _grayView = [[UIView alloc] initWithFrame:CGRectMake(0, 0, grayStar.size.width*5, grayStar.size.height)];
    [self addSubview:_grayView];

    _grayView.backgroundColor = [UIColor colorWithPatternImage:grayStar];

    _yellowView = [[UIView alloc] initWithFrame:CGRectMake(0, 0, yellowStar.size.width*5, yellowStar.size.height)];
    [self addSubview:_yellowView];

    _yellowView.backgroundColor = [UIColor colorWithPatternImage:yellowStar];

    CGFloat xScale = self.width/_grayView.width;
    CGFloat yScale = self.height/_grayView.height;

    _grayView.transform = CGAffineTransformMakeScale(xScale, yScale);
    _yellowView.transform = CGAffineTransformMakeScale(xScale, yScale);

    _grayView.center = CGPointMake(self.width/2, self.height/2);
    _yellowView.center = CGPointMake(self.width/2, self.height/2);

    _yellowView.left = _grayView.left;


}


@end
